home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 / Ham Radio 2000.iso / ham2000 / tcp_ip / ntp_src / ntp_cont.h < prev    next >
C/C++ Source or Header  |  1992-04-03  |  6KB  |  239 lines

  1. /*
  2.  * ntp_control.h - definitions related to NTP mode 6 control messages
  3.  */
  4. struct ntp_control {
  5.     u_char li_vn_mode;        /* leap, version, mode */
  6.     u_char r_m_e_op;        /* response, more, error, opcode */
  7.     u_short sequence;        /* sequence number of request */
  8.     u_short status;            /* status word for association */
  9.     u_short associd;        /* association ID */
  10.     u_short offset;            /* offset of this batch of data */
  11.     u_short count;            /* count of data in this packet */
  12.     u_char data[(480 + 12)];    /* data + auth */
  13. };
  14.  
  15. /*
  16.  * Length of the control header, in octets
  17.  */
  18. #define    CTL_HEADER_LEN        12
  19. #define    CTL_MAX_DATA_LEN    468
  20.  
  21.  
  22. /*
  23.  * Limits and things
  24.  */
  25. #define    CTL_MAXTRAPS    3        /* maximum number of traps we allow */
  26. #define    CTL_TRAPTIME    (60*60)        /* time out traps in 1 hour */
  27. #define    CTL_MAXAUTHSIZE    64        /* maximum size of an authen'ed req */
  28.  
  29. /*
  30.  * Decoding for the r_m_e_op field
  31.  */
  32. #define    CTL_RESPONSE    0x80
  33. #define    CTL_ERROR    0x40
  34. #define    CTL_MORE    0x20
  35. #define    CTL_OP_MASK    0x1f
  36.  
  37. #define    CTL_ISRESPONSE(r_m_e_op)    (((r_m_e_op) & 0x80) != 0)
  38. #define    CTL_ISMORE(r_m_e_op)    (((r_m_e_op) & 0x20) != 0)
  39. #define    CTL_ISERROR(r_m_e_op)    (((r_m_e_op) & 0x40) != 0)
  40. #define    CTL_OP(r_m_e_op)    ((r_m_e_op) & CTL_OP_MASK)
  41.  
  42. /*
  43.  * Opcodes
  44.  */
  45. #define    CTL_OP_UNSPEC        0
  46. #define    CTL_OP_READSTAT        1
  47. #define    CTL_OP_READVAR        2
  48. #define    CTL_OP_WRITEVAR        3
  49. #define    CTL_OP_READCLOCK    4
  50. #define    CTL_OP_WRITECLOCK    5
  51. #define    CTL_OP_SETTRAP        6
  52. #define    CTL_OP_ASYNCMSG        7
  53. #define    CTL_OP_UNSETTRAP    31
  54.  
  55. /*
  56.  * {En,De}coding of the system status word
  57.  */
  58. #define    CTL_SST_TS_UNSPEC    0    /* time source unspecified */
  59. #define    CTL_SST_TS_LF        1    /* time source LF radio */
  60. #define    CTL_SST_TS_UHF        2    /* time source UHF radio */
  61. #define    CTL_SST_TS_HF        3    /* time source HF radio */
  62. #define    CTL_SST_TS_LOCAL    4    /* time source LOCAL */
  63. #define    CTL_SST_TS_NTP        5    /* time source NTP */
  64. #define    CTL_SST_TS_UDPTIME    6    /* time source UDP/TIME */
  65. #define    CTL_SST_TS_WRSTWTCH    7    /* time source is wristwatch*/
  66.  
  67. #define    CTL_SYS_MAXEVENTS    15
  68.  
  69. #define    CTL_SYS_STATUS(li, source, nevnt, evnt) \
  70.         ((((li)<< 14)&0xc000) | \
  71.         (((source)<<8)&0x3f00) | \
  72.         (((nevnt)<<4)&0x00f0) | \
  73.         ((evnt)&0x000f))
  74.  
  75. #define    CTL_SYS_LI(status)    (((status)>>14) & 0x3)
  76. #define    CTL_SYS_SOURCE(status)    (((status)>>8) & 0x3f)
  77. #define    CTL_SYS_NEVNT(status)    (((status)>>4) & 0xf)
  78. #define    CTL_SYS_EVENT(status)    ((status) & 0xf)
  79.  
  80. /*
  81.  * {En,De}coding of the peer status word
  82.  */
  83. #define    CTL_PST_CONFIG        0x80
  84. #define    CTL_PST_AUTHENABLE    0x40
  85. #define    CTL_PST_AUTHENTIC    0x20
  86. #define    CTL_PST_REACH        0x10
  87. #define    CTL_PST_SANE        0x08
  88. #define    CTL_PST_DISP        0x04
  89.  
  90. #define    CTL_PST_SEL_REJECT    0
  91. #define    CTL_PST_SEL_SELCAND    1
  92. #define    CTL_PST_SEL_SYNCCAND    2
  93. #define    CTL_PST_SEL_SYSPEER    3
  94.  
  95. #define    CTL_PEER_MAXEVENTS    15
  96.  
  97. #define    CTL_PEER_STATUS(status, nevnt, evnt) \
  98.         ((((status)<<8) & 0xff00) | \
  99.         (((nevnt)<<4) & 0x00f0) | \
  100.         ((evnt) & 0x000f))
  101.  
  102. #define    CTL_PEER_STATVAL(status)(((status)>>8) & 0xff)
  103. #define    CTL_PEER_NEVNT(status)    (((status)>>4) & 0xf)
  104. #define    CTL_PEER_EVENT(status)    ((status) & 0xf)
  105.  
  106. /*
  107.  * {En,De}coding of the clock status word
  108.  */
  109. #define    CTL_CLK_OKAY        0
  110. #define    CTL_CLK_NOREPLY        1
  111. #define    CTL_CLK_BADFORMAT    2
  112. #define    CTL_CLK_FAULT        3
  113. #define    CTL_CLK_PROPAGATION    4
  114. #define    CTL_CLK_BADDATE        5
  115. #define    CTL_CLK_BADTIME        6
  116.  
  117. #define    CTL_CLK_STATUS(status, event) \
  118.         ((((status)<<8) & 0xff00) | \
  119.         ((event) & 0x00ff))
  120.  
  121. /*
  122.  * Error code responses returned when the E bit is set.
  123.  */
  124. #define    CERR_UNSPEC    0
  125. #define    CERR_PERMISSION    1
  126. #define    CERR_BADFMT    2
  127. #define    CERR_BADOP    3
  128. #define    CERR_BADASSOC    4
  129. #define    CERR_UNKNOWNVAR    5
  130. #define    CERR_BADVALUE    6
  131.  
  132. #define    CERR_NORESOURCE    CERR_PERMISSION    /* wish there was a different code */
  133.  
  134.  
  135. /*
  136.  * System variables we understand
  137.  */
  138. #define    CS_LEAP        1
  139. #define    CS_STRATUM    2
  140. #define    CS_PRECISION    3
  141. #define    CS_DISTANCE    4
  142. #define    CS_DISPERSION    5
  143. #define    CS_REFID    6
  144. #define    CS_REFTIME    7
  145. #define    CS_HOLD        8
  146. #define    CS_PEERID    9
  147. #define    CS_OFFSET    10
  148. #define    CS_DRIFT    11
  149. #define    CS_COMPLIANCE    12
  150. #define    CS_CLOCK    13
  151. #define    CS_LEAPIND    14
  152. #define    CS_LEAPWARNING    15
  153. #define    CS_PROCESSOR    16
  154. #define    CS_SYSTEM    17
  155. #define    CS_KEYID    18
  156. #define    CS_MAXSKEW    19
  157.  
  158. #define    CS_MAXCODE    CS_MAXSKEW
  159.  
  160. /*
  161.  * Peer variables we understand
  162.  */
  163. #define    CP_CONFIG    1
  164. #define    CP_AUTHENABLE    2
  165. #define    CP_AUTHENTIC    3
  166. #define    CP_SRCADR    4
  167. #define    CP_SRCPORT    5
  168. #define    CP_DSTADR    6
  169. #define    CP_DSTPORT    7
  170. #define    CP_LEAP        8
  171. #define    CP_HMODE    9
  172. #define    CP_STRATUM    10
  173. #define    CP_PPOLL    11
  174. #define    CP_HPOLL    12
  175. #define    CP_PRECISION    13
  176. #define    CP_DISTANCE    14
  177. #define    CP_DISPERSION    15
  178. #define    CP_REFID    16
  179. #define    CP_REFTIME    17
  180. #define    CP_ORG        18
  181. #define    CP_REC        19
  182. #define    CP_XMT        20
  183. #define    CP_REACH    21
  184. #define    CP_VALID    22
  185. #define    CP_TIMER    23
  186. #define    CP_ESTDELAY    24
  187. #define    CP_ESTOFFSET    25
  188. #define    CP_ESTDISP    26
  189. #define    CP_KEYID    27
  190. #define    CP_DELAY    28
  191. #define    CP_OFFSET    29
  192. #define    CP_PMODE    30
  193. #define    CP_RECEIVED    31
  194. #define    CP_SENT        32
  195. #define CP_VERSION    33
  196.  
  197. #define    CP_MAXCODE    CP_VERSION
  198.  
  199. /*
  200.  * Clock variables we understand
  201.  */
  202. #define    CC_TYPE        1
  203. #define    CC_TIMECODE    2
  204. #define    CC_POLL        3
  205. #define    CC_NOREPLY    4
  206. #define    CC_BADFORMAT    5
  207. #define    CC_BADDATA    6
  208. #define    CC_FUDGETIME1    7
  209. #define    CC_FUDGETIME2    8
  210. #define    CC_FUDGEVAL1    9
  211. #define    CC_FUDGEVAL2    10
  212. #define    CC_FLAGS    11
  213. #define    CC_DEVICE    12
  214.  
  215. #define    CC_MAXCODE    CC_DEVICE
  216.  
  217. /*
  218.  * Definition of the structure used internally to hold trap information.
  219.  * ntp_request.c wants to see this.
  220.  */
  221. struct ctl_trap {
  222.     struct sockaddr_in tr_addr;    /* address of trap recipient */
  223.     struct interface *tr_localaddr;    /* interface to send this through */
  224.     u_long tr_settime;        /* time trap was set */
  225.     u_long tr_count;        /* async messages sent to this guy */
  226.     u_long tr_origtime;        /* time trap was originally set */
  227.     u_long tr_resets;        /* count of resets for this trap */
  228.     u_short tr_sequence;        /* trap sequence id */
  229.     u_char tr_flags;        /* trap flags */
  230.     u_char tr_version;        /* version number of trapper */
  231. };
  232.  
  233. /*
  234.  * Flag bits
  235.  */
  236. #define    TRAP_INUSE    0x1        /* this trap is active */
  237. #define    TRAP_NONPRIO    0x2        /* this trap is non-priority */
  238. #define    TRAP_CONFIGURED    0x4        /* this trap was configured */
  239.